package com.yvon.service.demo.algorithm.offer;

/**
 * 写一个函数，输入 n ，求斐波那契（Fibonacci）数列的第 n 项（即 F(N)）
 * https://doocs.github.io/leetcode/#/lcof/%E9%9D%A2%E8%AF%95%E9%A2%9810-%20I.%20%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/README
 */
public class P10 {
    public static void main(String[] args) {
        Solution solution = new P10().new Solution();
        System.out.println(solution.fib(10));
    }

    class Solution {
        public int fib(int n) {
            int a = 0, b = 1;
            for (int i = 0; i < n; i++) {
                int c = (a + b) % 1000000007;
                a = b;
                b = c;
            }
            return a;
        }
    }
}
